import { useRef, useState } from 'react';
import { FormGroup, DATA_ENTRY } from '@/src/components/index';
import { FirstHeaderC, PrimaryC, SecondHeaderC } from '@/src/comps';
import { Space } from 'antd';

const BussinessDemo = () => {
  const FormGroupRef = useRef();
  const [p4, setP4] = useState();
  const [c4, setC4] = useState();

  const onChange5 = (e) => {
    setP4(e.province);
    setC4(e.city);
  };
  return (
    <div>
      <FirstHeaderC title='业务相关' />
      <SecondHeaderC title='获取表单值在控制台' />
      <Space>
        <PrimaryC
          title='获取表单值'
          onClick={async () => {
            const formValues = await FormGroupRef.current.getFormGroupData();
            console.log(formValues);
          }}
        />
        <PrimaryC
          title='重置表单值'
          onClick={() => {
            FormGroupRef.current.resetFields();
          }}
        />
      </Space>
      <FormGroup
        dataSource={[
          {
            dataIndex: 'SERIESPRODUCTGROUP',
            type: DATA_ENTRY.SERIESPRODUCTGROUP,
            initialValue: '6ca04893d1534db6ab2930514b857a7e',
            disabled: true,
            rules: [{ required: true, message: '请选择系列产品!' }],
          },
          {
            dataIndex: 'productGroupId',
            type: DATA_ENTRY.PRODUCTGROUP,
            rules: [{ required: true, message: '请选择产品组!' }],
            onChange: (e) => {},
            tradeModel: ['BOOKKEEPING_MODE', 'COMMAND_MODE'], // 不包含估值解析和估值对接的产品
          },
          {
            title: ['产品', '组合'],
            type: DATA_ENTRY.PRODUCTGROUPSEP,
            authority: 'write',
            multipleGroup: false,
            dataIndex: ['productid', 'portfolioid'],
            rules: [[{ required: true, message: '请选择产品!' }], [{ required: true, message: '请选择组合!' }]],
            groupOnChange: (e) => {},
            productOnChange: (e) => {},
            allowClear: false,
            exist: 1,
          },
          {
            dataIndex: 'zqdm',
            title: '证券代码',
            type: DATA_ENTRY.SECURITIESCODE,
            onChange: (e) => {},
            rules: [{ required: true, message: '请选择证券代码!' }],
          },
          {
            title: '交易方向', // 显示名称
            dataIndex: 'direction', // Form识别的Item ID
            businessType: '12',
            type: DATA_ENTRY.TRADINGDIRECT,
            initialValue: undefined,
            allowClear: false,
            rules: [{ required: true, message: '请选择交易方向!' }],
          },
          {
            // 业务目标
            dataIndex: 'bussinessObjectives',
            type: DATA_ENTRY.BUSINESSTARGETC,
            initialValue: undefined,
          },
          {
            dataIndex: 'SPPI_result',
            type: DATA_ENTRY.SPPIRESULTC,
            title: 'SPPI结果',
            initialValue: undefined,
            selectProps: {
              SecuritiesCode1: '',
              rightContentShow: false, // 右侧按钮是否展示，后面展示后的禁用逻辑，展示逻辑，组件控制
              SppItype: 3,
              sppITitle: '新增测试',
            },
          },

          {
            dataIndex: 'TRADINGTYPE',
            type: DATA_ENTRY.TRADINGTYPE,
            disabled: true,
            initialValue: '2',
            span: 8,
          },
          {
            dataIndex: 'TradingCompanyC',
            type: DATA_ENTRY.TRADINGCOMPANY,
            disabled: true,
            initialValue: '测试会员',
          },
          {
            dataIndex: 'TRADINGMARKET',
            type: DATA_ENTRY.TRADINGMARKET,
          },
          {
            dataIndex: 'fundUseIndustry', // 资金运用行业
            type: DATA_ENTRY.FUNDAPPLICATIONINDUSTRYC,
            title: '资金运用行业',
            rules: [{ required: false, message: '请选择资金运用行业' }],
          },
          // 基准
          {
            dataIndex: 'bench8',
            type: DATA_ENTRY.BENCHMARK,
            initialValue: undefined,
          },
          // 行业
          {
            dataIndex: 'industry',
            type: DATA_ENTRY.INDUSTRYC,
            initialValue: undefined,
          },
          // wind债券类型
          {
            dataIndex: 'WINBONDTYPE',
            type: DATA_ENTRY.WINBONDTYPE,
            initialValue: undefined,
          },
          // 租户
          {
            dataIndex: 'tenant',
            type: DATA_ENTRY.TENANT,
            initialValue: undefined,
          },
          // 租户+部门
          {
            dataIndex: 'TENANTDEPARTMENT',
            type: DATA_ENTRY.TENANTDEPARTMENT,
            initialValue: undefined,
          },
          {
            dataIndex: 'RATERANGEC',
            type: DATA_ENTRY.RATERANGEC,
            initialValue: undefined,
            title: '评级区间',
          },
          // 省市
          {
            dataIndex: 'ADDRESSC',
            type: DATA_ENTRY.ADDRESSC,
            initialValue: undefined,
            onChange: (e) => {
              onChange5(e);
            },
            provinceDataIndex: 'p4',
            cityDataIndex: 'c4',
          },
        ]}
        onRef={(ref) => {
          FormGroupRef.current = ref;
        }}
      />
    </div>
  );
};

export default BussinessDemo;
